package flyweight.tree;

import java.util.HashMap;

/**
 * 享元工厂
 * 决定是否复用已有享元或者创建一个新的对象。
 */
public class TreeFactory {
    private final static HashMap<String, TreeType> map = new HashMap<>();

    public static TreeType getTreeType(String name, String color, String texture) {
        String key = name + "_" + color + "_" + texture;
        TreeType treeType = map.get(key);
        if (treeType == null) {
            treeType = new TreeType(name, color, texture);
            map.put(key, treeType);
        }
        return treeType;
    }
}